package com.dushibao.manage.dashboard.website;

import com.alibaba.fastjson2.JSON;
import com.dushibao.entity.WebSite;
import com.dushibao.service.WebsiteService;
import com.dushibao.service.impl.WebsiteServiceImpl;
import com.dushibao.view.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 站点设置
 */
@WebServlet("/dashboard/website/settings")
public class SettingsServlet extends HttpServlet {
    WebsiteService websiteService = new WebsiteServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String,Object> maps = new HashMap<>();
        maps.put("obj",websiteService.getOne());

        ModelAndView mv = new ModelAndView("dashboard/website/settings",maps);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        BufferedReader bw = req.getReader();
        String json = bw.readLine();

        WebSite webSite = JSON.parseObject(json,WebSite.class);

        resp.getWriter().write(websiteService.saveOrUpdate(webSite).toString());

    }
}
